package com.shop.cereshop.app.utils;

//import io.geekidea.springbootplus.framework.common.api.ApiResult;
import net.sf.json.JSONObject;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * @program: dlshop
 * 描述：
 * @author: 我好帅
 * @create: 2021-07-10 16:57
 **/
public class GZHUtil {
    public static JSONObject judgeIsFollow(String token,String openid){
        JSONObject demoJson = null;
        String url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token="+token+"&openid="+openid+"&lang=zh_CN";
//        https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN
        try {
            URL urlGet = new URL(url);
            HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
            http.setRequestMethod("GET"); // 必须是get方式请求
            http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
            http.setDoOutput(true);
            http.setDoInput(true);
            http.connect();
            InputStream is = http.getInputStream();
            int size = is.available();
            byte[] jsonBytes = new byte[size];
            is.read(jsonBytes);
            String message = new String(jsonBytes, "UTF-8");
            demoJson = JSONObject.fromObject(message);
            //System.out.println("JSON字符串："+demoJson);
             is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return demoJson;
    }
}
